package dbobj

import (
	"gitee.com/KotlinToGo/orm"
	_ "github.com/mattn/go-sqlite3"
)

func init() {
	GetSqliteEngine()
}

func GetMysqlEngine() *orm.Engine {
	var err error
	var engine *orm.Engine
	engine, err = orm.Open(&orm.Config{
		Driver: "mysql",
		Dsn:    "root:123456@tcp(localhost:3306)/test?charset=utf8mb4",
		Prefix: "nv_",
	})
	if err != nil {
		panic(err.Error())
	}
	return engine
}

var engine *orm.Engine
func GetSqliteEngine() *orm.Engine {
	var err error
	engine, err = orm.Open(&orm.Config{
		Driver: "sqlite3",
		Dsn:    "./db.sqlite",
		Prefix: "",
	})
	if err != nil {
		panic(err.Error())
	}
	return engine
}

func GetDB() orm.IOrm {
	return engine.NewOrm()
}
